package com.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author wangjg
 * @date 2023/11/1 15:15
 * @Description: 首页跳转servlet
 */
@WebServlet(name = "BlankServlet")
public class BlankServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        HttpSession session = request.getSession();
        Object currentUserType = session.getAttribute("currentUserType");
        if("admin".equals(currentUserType)) {
            request.setAttribute("mainPage", "admin/blank.jsp");
            request.getRequestDispatcher("mainAdmin.jsp").forward(request, response);
        } else if("student".equals(currentUserType)) {
            request.setAttribute("mainPage", "student/blank.jsp");
            request.getRequestDispatcher("mainStudent.jsp").forward(request, response);
        }
    }
}
